package com.wohuijituan.whcsmerchant.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.WindowManager;

import com.wohuijituan.whcsmerchant.R;
import com.wohuijituan.whcsmerchant.utils.MyKey;


/**
 * 说明：
 * 作者：陈杰宇
 * 时间： 2016/3/7 10:40
 * 版本：V1.0
 * 修改历史：
 */
public class WelcomeActivity extends MyBaseActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_welcome);
        initData();
        jump2Main();
    }

    private void initData() {
        SharedPreferences sp = getSharedPreferences(MyKey.userConfig, MODE_PRIVATE);
        String userKey = sp.getString("userKey","");
        myApplication.setUserKey(userKey);
    }

    /**
     * 跳转到主页
     */
    private void jump2Main() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                handler.sendEmptyMessage(10000);
            }
        }).start();
    }

    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            Intent intent = new Intent(WelcomeActivity.this, HomeActivity.class);
            if (isLogin()){
                intent.setClass(WelcomeActivity.this, HomeActivity.class);//如果用户登录了
                startActivity(intent);
            }else {
                login(intent);//如果用户没有登录跳转到登录界面
            }

            finish();
        }
    };
}
